package com.itheima.common;


/**
 * 基于ThreadLocal封装工具类，用户保存和获取当前登录用户id
 */
public class BaseContext {
    /**
     * 通过ThreadLocal的get和set方法得到用户id
     */
    private static final ThreadLocal<Long> THREAD_LOCAL=new ThreadLocal<>();

    public static Long getCurrentId() {
        /**
         * 获取用户
         */
        return THREAD_LOCAL.get();
    }

    public static void setCurrentId(Long id) {
        /**
         * 添加用户
         */
        THREAD_LOCAL.set(id);
    }
}
